<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        {{message}}
        <html-child @child-event="parentFunc"></html-child>
    </div>

    <template id="html-child">
        <div>
            <button @click="childClick(name)">{{name}}</button>
        </div>
    </template>


    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        
        var app = new Vue({
            el:"#app",
            data:{
                message:"hello,vue"
            },  
            components:{
                'html-child':{
                    data() {
                        return {
                            name:"marscarm"
                        }
                    },
                    template:"#html-child",
                    methods:{
                        childClick(name){
                            // console.log(name)
                            this.$emit('child-event',name)
                        }//虽然可以通过自定义事件的方法实现子组件改变父组件，但还是不建议这样做
                    }
                    
                }
            },
            methods: {
                parentFunc(name){
                    this.message=name;
                }
            },
        })
    </script>

</body>
</html>